Skip to main content

Sorting II (2)

  1. Merge Sort
    • Recursive call, then merge
    • For merge
      • Extract size
      • Extract item
      • Merge
      • Reassign item
      • All condition for resiging/extracting should follow less than equal format
    • (l>r) condition may causes infinitie recursion, use (l>=r) instead.
    • Left half is [l...m] and right half is [m+1...r]
  2. Recursive Bubble Sort
    • Set the termination condition properly (at begin)
    • Replace the outer loop with recursive call (at end, can work before loop as well)
  3. Recursive Insertion Sort
    • Just replace the outer loop with one paramter
  4. Quick Sort
    1. 10 April, 2026: 00.23.32 ❌
      • Failed at implmentation

        • Kind of reverse approach of merge, get partitioned inex, recursive call based on the partition index
        • Place the pivot at right place
        StepLowHighSubarrayPivotPivot Index After PartitionArray State After Step
        106[8, 3, 1, 7, 0, 10, 2]22[1, 0, 2, 7, 8, 10, 3]
        201[1, 0]00[0, 1, 2, 7, 8, 10, 3]
        336[7, 8, 10, 3]33[0, 1, 2, 3, 8, 10, 7]
        446[8, 10, 7]74[0, 1, 2, 3, 7, 10, 8]
        556[10, 8]85[0, 1, 2, 3, 7, 8, 10]